<?php
class models_khachhang extends  connect
{
	function _listkhachhang(){
		/*$sql = 'SELECT kh.MaKH, kh.TenKH, kh.DiaChi, kh.SDT,lh.TenLH 
				FROM khachhang kh, loaihang lh
				WHERE kh.MaLH = lh.MaLH';*/
		$sql = 'SELECT MaKH, TenKH, DiaChi, SDT
				FROM khachhang';
		$this->query_db($sql);
		return $this->fetchAll();
	}
	
	function _addkhachhang($TenKH,$DiaChi,$SDT){
		$sql = "INSERT INTO khachhang VALUES('','$TenKH','$DiaChi','$SDT')";
		$this->query_db($sql);
	}
	
	function _delKhachHang($id){
		$sql = "DELETE 
				FROM khachhang 
				WHERE MaKH = '$id'";
		
		$this->query_db($sql);
	}
	
	function _getKhachHang($id){
		$sql = "SELECT *
				FROM khachhang 
				WHERE MaKH = '$id'";
		$this->query_db($sql);
		return $this->fetchOne();	
	}
	
	function _updateKhachHang($TenKH, $DiaChi, $SDT, $id)
	{
		$sql = "UPDATE khachhang 
				SET TenKH = '$TenKH', DiaChi = '$DiaChi', SDT = '$SDT'
				WHERE MaKH = $id";
		$this->query_db($sql);
	}
} 
?>